
<!-- <html>
<head>
<style type="text/css">
div {background-color:#b0c4de;}
#myTitle {max-width:700px; border:2px solid #3b5998;}
#mainSection {width:700px; height:700px; border:2px solid #3b5998;}
</style>
</head>

<body>
<!--   <div style="width:700px; height:700px; border:1px; border-color:#3b5998; "> -->
<!-- <div id="myTitle"><center><img src="http://localhost/entireLogo.jpg" alt="MosaicIT!"/></center>
<br> 
<center>
Convert your display pic into a mosaic!
</center>
</div>
<br>
<div id="mainSection">-->
<html>
<head>
<style type="text/css">

/*<!-- Image Styles -->  */
div.img
  {
  margin:2px;
  border:1px solid #0000cc;
  height:auto;
  width:auto;
  float:left;
  text-align:center;
  position:fixed;
  bottom:30px;
  right:40px;
  }
div.img1 img
  {
  display:inline;
  margin:20px;
  border:5px solid #ffffff;
  }
  div.img1
  {
  margin:2px;
  border:1px solid #0000cc;
  height:auto;
  width:auto;
  float:left;
  text-align:center;
  position:fixed;
  bottom:30px;
  left:70px;
  }
div.img img
  {
  display:inline;
  margin:20px;
  border:5px solid #ffffff;
  }
div.desc
  {
  text-align:center;
  font-weight:normal;
  width:120px;
  margin:20px;
  }
  div {background-color:#b0c4de;}

div.mosaic
  {
   margin:2px;
   padding: 10px;
  border:5px solid #0000cc;
  height:auto;
  width:auto;
  float:left;
  text-align:center;
  }
  
  div.mosaic img
  {
  display:inline;
  margin:3px;
  border:3px solid #ffffff;
  }
  
  div.arrow
  {
  height:auto;
  width:auto;
  float:left;
  text-align:center;
  position:fixed;
  bottom:30px;
  left:30px;
  }
  
  div.arrow img
  {
   margin:20px;
  display:inline;
 
  }
div.mosaic a:hover img
  {
  border:1px solid #000000;
  }


/*<!-- Image Links (Download) -->  */
a:link {color:#000000;}    /* unvisited link */
a:visited {color:#000000;} /* visited link */
a:hover {color:#0000CC;}   /* mouse over link */
a:active {color:#000000;}  /* selected link */

#myTitle {max-width:700px; border:2px solid #3b5998;}
#mainSection {width:700px; height:700px; border:2px solid #3b5998;}

#navlist{position:relative;}
#navlist li{margin:0;padding:0;list-style:none;position:absolute;top:0;}
#navlist li, #navlist a{height:44px;display:block;}

#next{left:300px;top:300px;width:43px;}
#next{background:url('http://t2.gstatic.com/images?q=tbn:ANd9GcRcgQCpn3JlKX6h0bUSMMzL2Ke12Fu3jiRbYsC6DczVb28moCtJlw') 0 0;}

</style>
</head>
<body>



<div id="myTitle"><center><img src="http://localhost/entireLogo.jpg" alt="MosaicIT!"/></center>
<br> 
<center>
<b>Mosaic Your Image!</b>
</center>
</div>
<br>
<div id="mainSection">
<br> 
<!-- <b>Choose the Image for Mosaic Effects and CLick MosaicIT!</b>-->
<br>
<div class="img">
  <a target="_blank">
  <img src="https://3437566319875966611-a-1802744773732722657-s-sites.googlegroups.com/site/photograhy6734/documents/duck.jpg?attachauth=ANoY7crC2x26WglmVZq6hYdl3Pz-H2Pum9k9YLfhivU77ozegAfPyUjnZtybSyUrVF9Bx7lz5XmZ7s_DmOz9rIJmZ9AM-pA56JWk6lSH8zIoVUg1kwlzxFyfMP5Ut70NR7TXDaZ9DK5--_Lr2KTdNBDHJwELzcC8oS-8-dflIuWFpnuoanCaN07zaozyFGFLQoBlQsvj2g2rNjmQkw9wSCXoFD-iBwuURA%3D%3D&attredirects=0" alt="Image1" width="130" height="130" />
  </a>
  </div>
  
 <div class="arrow">
  <a target="_blank">
  <img src="https://3437566319875966611-a-1802744773732722657-s-sites.googlegroups.com/site/photograhy6734/documents/arrow.png?attachauth=ANoY7cqJdwRlZjGlnraod31_4gUR2aKnuh8gOxOTNf69QS-xal3Q8i7xf4RmPkieTWNg_4uyRRg_yC7PawfvEVSNRFG6IX-ra-sWVOg78MRs8KYyETWR8YwEmqI8y42qH8CyEnApo_PCaLKh2nrlMhLmlijVtDZizZGnXUMGDYYxlVL-s6h4-r7V4Tc3TWXkslOOeq1aXvryWVPANCzBXL_3gevHV3qGjA%3D%3D&attredirects=0" alt="Image1" width="110" height="110" />
  </a>
  </div>
  
  
<div class="img1">
  <a target="_blank">
  <img src="https://3437566319875966611-a-1802744773732722657-s-sites.googlegroups.com/site/photograhy6734/documents/duckMosaic.jpg?attachauth=ANoY7cpyVi1yO7CvyQAm_oo8_1ciOwN4AiscNtCpnZectbly0HwXelIWwwVwFqdODtobMDCx7Xoa0ZKluiOlZrrmMsuX5Dlp2BBnse7KyqMxBTJzrV9H7BsgZSK36H7tuHPsBIVYO9yNMjvLvck97iK8e4mDFiCvRd8r2MoofIjHZh8sUCSdEkIToIL-GfSAE6D-ne714TzWcjkK-mk7j_WAMpXsViswYA%3D%3D&attredirects=0" 
  alt="Image1" width="130" height="130" />
  </a>
</div>


<!-- <div class="img">
  <a target="_blank">
  <img src="http://t2.gstatic.com/images?q=tbn:ANd9GcTSbrqTpH63zGW4ijJoVtENeBNBmVd3OzZcAG8xurffbhNQBDFE" alt="Image1" width="110" height="90" />
  </a>
  <div class="desc" ><p><b><a href="default.asp" target="_blank">MosaicIT</a></b></p></div>
</div>
<div class="img">
  <a target="_blank" >
  <img src="http://t1.gstatic.com/images?q=tbn:ANd9GcQT3yjP_bAlrohQwgFjXoZDVkDlzfw2SXmNtkQH80qiCm1prHZX4g" alt="Image2" width="110" height="90" />
  </a>
  <div class="desc"><p><b><a href="default.asp" target="_blank">MosaicIT</a></b></p></div>
</div>-->


<!-- <ul id="navlist">
  <li id="next"><a href="css_syntax.asp"></a></li>
</ul>-->


<!-- <div class="mosaic">
  <a target="_blank" >
  <center>
  <img src="http://t1.gstatic.com/images?q=tbn:ANd9GcQT3yjP_bAlrohQwgFjXoZDVkDlzfw2SXmNtkQH80qiCm1prHZX4g" alt="Image2" width="300" height="300" />
  </center>
  </a>
  
</div>-->
<?php 
//require 'curl.php';

	//asking the user for permission

     $app_id = "216401685037550";

     $canvas_page = "http://apps.facebook.com/comphotography/";
/*
     $auth_url = "http://www.facebook.com/dialog/oauth?client_id=" 
            . $app_id . "&redirect_uri=" . urlencode($canvas_page)."&scope=user_photos";

     $signed_request = $_REQUEST["signed_request"];

     list($encoded_sig, $payload) = explode('.', $signed_request, 2); 

     $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

     if (empty($data["user_id"])) {
            echo("<script> top.location.href='" . $auth_url . "'</script>");
     } else {
            echo ("Welcome User: " . $data["user_id"]);
     } 
*/     
     //authenticate MosaicIT with facebook
     
    $app_secret = "b4c96a8cf5ec742774bbf84ee9b53ce6";
   // $my_url = "http://www.yahoomail.com";

    $code = $_REQUEST["code"];

    if(empty($code)) {
        $dialog_url = "http://www.facebook.com/dialog/oauth?client_id=" 
            . $app_id . "&redirect_uri=" . urlencode($canvas_page)."&scope=user_photos";

        echo("<script> top.location.href='" . $dialog_url . "'</script>");
    }

    $token_url = "https://graph.facebook.com/oauth/access_token?client_id="
        . $app_id . "&redirect_uri=" . urlencode($canvas_page) . "&client_secret="
        . $app_secret . "&code=" . $code;

        //echo $code;
    $access_token = file_get_contents($token_url);

    //echo "This is ACCESS T";
    //echo $access_token;
    
    $graph_url = "https://graph.facebook.com/me?" . $access_token;

    //$graph_url;
    $user = json_decode(file_get_contents($graph_url));

    //Uploading
    
    // Get a list of the users albums
    /*$album_name_given_by_user="Funny Photos";
	$create_album="";
	$flag_for_album_created=array();
	$image_url=$_REQUEST['img'];
	$albums = $facebook->api_client->photos_getAlbums($user, null);
	// Pick the album for sake of the example
                $aid_arr=array();
                for($i=1; $i < count($albums); $i++){
                                if($albums[$i]['name']==$album_name_given_by_user){
                                                $flag_for_album_created[].="yes";
                                }else{
                                                $flag_for_album_created[].="no";
                                }
                }//for loop ends
 
                if(in_array("yes",$flag_for_album_created)){       
                                for($i=0; $i < count($albums); $i++){
                                                if($albums[$i]['name']==$album_name_given_by_user){
                                                                $aid_arr[] .= $albums[$i]['aid']."|".$albums[$i]['link'];
                                                }
                                }//for loop ends
                }else{
                                $create_album=$facebook->api_client->photos_createAlbum($album_name_given_by_user, null, $album_name_given_by_user);
                                $aid_arr[] .= $create_album['aid']."|".$create_album['link'];
                }//else ends
 
                $aid_arr_split = explode("|",$aid_arr[0]);
                $aid=$aid_arr_split[0];
                $album_url=$aid_arr_split[1];
 
	$filename = $image_url;
	$caption = 'This photo created using http://<server name>/<app name>/';
	 
	// Perform the upload and get the return data (including the URL of the new photo)
	$upload_result = $facebook->api_client->photos_upload($filename, $aid, $caption);//$aid
	*/
  //Uploading ends here
    

    //echo $user; -- this does not work
    
    //echo("Hello " . $user->name);
    $id = trim($user->id);
    $url = "https://graph.facebook.com/".$id."/picture";
    //$img = file_get_contents('https://graph.facebook.com/'.$user->id.'/picture?type=large');
    
    //$img = json_decode(file_get_contents($img));
   // echo $dPickURL;
    //$img = json_decode($img);

     //<img src="https://graph.facebook.com/".$user->name."/picture"/>
     
   // $img = file_get_contents('https://graph.facebook.com/'.$fid.'/picture?type=large');
    //$file = dirname(__file__).'/avatar/'.$user->id.'.jpg';
     //$file = dirname('/Desktop/PhotographyProject/Facebook').'/profilepic/'.$user->id.'.jpg';
      $file = dirname('/Desktop/PhotographyProject/Facebook').$user->id.'.jpg';
   // file_put_contents($file, $img);
    
   // $img = exec("matlab -r");
    //echo $img;
    /*$photo="https://graph.facebook.com/me/picture?access_token=".$session['access_token'];

    $sample = new sfFacebookPhoto;

    $thephotoURL=$sample->getRealUrl($photo);

    echo $thephotoURL;*/
    
   
/*$sourceFilePath = CurlHelper::downloadFile($img, array(
  'followLocation' => true,
  'maxRedirs' => 5,
));*/

     
    
 ?>
 
 <div class="mosaic">
  <a target="_blank" >
  <center>
  <!-- <img src="http://t1.gstatic.com/images?q=tbn:ANd9GcQT3yjP_bAlrohQwgFjXoZDVkDlzfw2SXmNtkQH80qiCm1prHZX4g" alt="Image2" width="300" height="300" />-->
   <img src="https://graph.facebook.com/<?= $user->id ?>/picture?type=large">
  </center>
  </a>
</div>

<!-- <img src="<? echo $dPickURL?>" alt="Display Picture"> -->
 <!-- <img src="https://graph.facebook.com/<?= $fid ?>/picture"> -->
 <!-- <img src="https://graph.facebook.com/<?= $user->id ?>/picture?">-->
 
<!-- width: 200px -->

<!-- <img src="https://graph.facebook.com/<?= $fid ?>/picture?type=large"> -->

<?php 

?>
</div>
</body>

</html>



